import { defineStore } from 'pinia';
import { getCategories } from '@/api/category'; // 假设您有一个API文件

export const useCategoryStore = defineStore('category', {
  state: () => ({
    categories: [] as Array<{ id: number; name: string; description: string }>
  }),
  actions: {
    async fetchCategories() {
      try {
        const response = await getCategories();
        this.categories = response;
        return response;
      } catch (error) {
        console.error('获取分类列表失败:', error);
        return [];
      }
    },
    async addCategory(category: { name: string; description: string }) {
      // 调用API添加分类
    },
    async deleteCategory(id: number) {
      // 调用API删除分类
    }
  }
}); 